package router

import (
	"crow-k8s/src/config"
	"crow-k8s/src/service"
	"github.com/gin-gonic/gin"
)

// GetReplicasetList 查看RS
// @Summary 查看RS
// @Description 查看指定Deployment的RS
// @Tags RS
// @Param namespace_name query string true "namespace名字"
// @Param deployment_name query string true "deployment的名字"
// @Success 200 {object} response.Response{data=v1.ReplicaSetList} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/k8s/replicaset/list [get]
// @Security Bearer
func GetReplicasetList(c *gin.Context) {
	namespaceName := c.Query("namespace_name")
	deploymentName := c.Query("deployment_name")
	rsList, err := service.GetReplicaSetList(config.K8sClientSet, namespaceName, deploymentName)
	for err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, rsList)
}

// GetReplicaset 查看指定RS
// @Summary 查看指定RS
// @Description 查看指定RS的信息
// @Tags RS
// @Param namespace_name query string true "namespace名字"
// @Param replicaset_name query string true "RS的名字"
// @Success 200 {object} response.Response{data=v1.ReplicaSet} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/k8s/replicaset [get]
// @Security Bearer
func GetReplicaset(c *gin.Context) {
	namespaceName := c.Query("namespace_name")
	replicasetName := c.Query("replicaset_name")
	rsInfo, err := service.GetReplicaSet(config.K8sClientSet, namespaceName, replicasetName)
	for err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, rsInfo)
}
